Skip to content

Add BitArray HasAllSet, HasAnySet and PopCount - #587

Merged
SimonCropp merged 1 commit into
mainfrom
bitarray
Sep 9, 2026
Merged

Add BitArray HasAllSet, HasAnySet and PopCount#587
SimonCropp merged 1 commit into
mainfrom
bitarray

Conversation

@SimonCropp

Copy link
Copy Markdown
Owner

Adds the three BitArray bit-population members:

  • HasAllSet() and HasAnySet(), added in net8
  • PopCount(), added in net11

BitArray had no polyfills at all, so this adds the section. API count 1052 to 1055.

Semantics

Checked against net11 rather than assumed:

empty all clear all set mixed
HasAllSet() true false true false
HasAnySet() false false true true
PopCount() 0 0 length count

The one that could catch an implementation out is HasAllSet() on an empty BitArray, which is true because the condition is vacuous.

The tests parameterise over lengths of 31, 32, 33, 64 and 100, since BitArray stores bits in an int[] and the unused high bits of the last word must not be counted. Each case is also checked with the final bit cleared.

The BCL implementations work a word at a time and these are bit at a time, but both are linear in the length, so no //Note: was added.

Verification

  • Solution builds clean in Release. Consume builds clean in Debug across all 22 target frameworks.
  • Tests green on net11.0 (1645), net462 (1622), net8.0 (1642) and net10.0 (1645), plus PublicTests, EmbeddedTests, UnsafeTests, NoRefsTests and NoExtrasTests.
  • net8.0 is a useful case here, since it exercises the BCL for HasAllSet and HasAnySet and the polyfill for PopCount, against the same assertions.

* HasAllSet() and HasAnySet(), added in net8
* PopCount(), added in net11

BitArray had no polyfills at all, so this adds the section.

HasAllSet returns true for an empty BitArray, matching net11, since the
condition is vacuous. Tests cover lengths either side of a 32 bit word
boundary, because the unused high bits of the last word must not be
counted.
@SimonCropp SimonCropp added this to the 11.3.0 milestone Sep 9, 2026
@SimonCropp
SimonCropp merged commit 6606657 into main Sep 9, 2026
4 of 6 checks passed
@SimonCropp
SimonCropp deleted the bitarray branch September 9, 2026 13:27
This was referenced Sep 10, 2026
This was referenced Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant